{% extends 'WebQuant/base.html' %}
{% block title %}每日持仓{% endblock %}
{% block content %}
{% include 'WebQuant/strategy_nav.html' %}
<div style="overflow:hidden">
    {% include 'WebQuant/strategy_nav_left.html' %}
    <div class="right_cont">
        {% include 'WebQuant/strategy_info_digest.html' %}
        <div class="daily_bottom">
            <div class="table_head">
                <div class="table_h1">日期</div>
                <div class="table_h2">股票代码</div>
                <div class="table_h3">收盘价（元）</div>
                <div class="table_h4">股数</div>
                <div class="table_h5">持仓（元）</div>
                <div class="table_h6">收益（元）</div>
            </div>
            <ul class="table_data">
            </ul>
            <div class="page"><p></p></div>
        </div>
    </div>
</div>

<script src="/static/WebQuant/js/mustache.min.js"></script>
<script src="/static/WebQuant/js/result.js"></script>
<script src="/static/WebQuant/js/page.js"></script>
<script src="/static/WebQuant/js/base.js"></script>
<script src="/static/WebQuant/js/strategy_info_digest.js"></script>
<script id="template" type="x-tmpl-mustache">
	[[#returnList]]
	<li>
		<div class="date">
			[[date]]
		</div>
		<div class="table_data_right">
			<div class="line">
				<div class="tables_d1">[[stockName]] <span>[[stockID]]</span></div>
				<div class="tables_d2">[[closePrice]]</div>
				<div class="tables_d3">[[stockNum]]</div>
				[[&positionValue]]
				[[&return]]
			</div>
			<div class="tables_d6">
				[总资产 <span>￥[[totalValue]]</span>	剩余金额<span>￥[[totalCash]]</span>	总交易成本<span>￥[[totalCommission]]</span>]
			</div>
		</div>
	</li>
	[[/returnList]]
</script>
<script>
Mustache.tags = ['[[', ']]']
	function ajaxpost_daily(index, init){
		$.post("/api/dailyposition",{
		index,index
		},function(data){
			for(var i =0 ;i<data.returnList.length;i++){

				data.returnList[i].return = parseFloat(data.returnList[i].return).toFixed(3);
				if(parseFloat(data.returnList[i].positionValue)>0){

					data.returnList[i].positionValue = '<div class="tables_d4" id="c_red">￥'+data.returnList[i].positionValue +'</div>';
				}else{

					data.returnList[i].positionValue = '<div class="tables_d4" id="c_green">￥'+data.returnList[i].positionValue+'</div>';
				}
				if(parseFloat(data.returnList[i].return)>0){

					data.returnList[i].return = '<div class="tables_d5 " id="c_red">￥'+data.returnList[i].return+'</div>';
				}else{

					data.returnList[i].return = '<div class="tables_d5 " id="c_green">￥'+data.returnList[i].return+'</div>';
				}
			}
			var template = $('#template').html();
			Mustache.parse(template);
			var rendered = Mustache.render(template, data);
			$('.table_data').html(rendered);
			if (init == 1) {
				$(".page p").createPage({
				  pageCount:data.pageCount,
				  current:index,
				  backFn:function(p){
					  ajaxpost_daily(p, 0);
				  }
				});
			}
		})
	}
ajaxpost_daily(1, 1);
</script>
{% endblock %}